package app.controller.msgmanage;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import app.entity.UserSession;
import app.service.VoiceAlertService;
import app.utils.Common;
import app.utils.DataResponse;

@Controller("VoiceAlertController")
public class VoiceAlertController {
	@Autowired
	@Qualifier("VoiceAlertService")
	private VoiceAlertService voiceAlertService;
	@RequestMapping("/voice_alert")
	public void changeVoiceAlert(HttpServletResponse response,HttpSession session){
		UserSession user = (UserSession) session.getAttribute(Common.sessionUser);
		if (user!=null) {
			int changVoiceALert = voiceAlertService.changVoiceALert(user.getId());
			DataResponse.jsonResponse(response, changVoiceALert);
			return;
		}
		DataResponse.jsonResponse(response, 0);
		return;
	}
	@RequestMapping("/voice_alert_info")
	public void getVoiceAlert(HttpServletResponse response,HttpSession session){
		UserSession user = (UserSession) session.getAttribute(Common.sessionUser);
		if (user!=null) {
			String userVoiceAlert = voiceAlertService.getUserVoiceAlert(user.getId());
			DataResponse.jsonResponse(response, userVoiceAlert);
			return;
		}
		DataResponse.jsonResponse(response, 1);
		return;
	}
}
